﻿package src.software 
{
	import flash.display.Shape;
	import flash.events.Event;
	import flash.utils.getTimer;
	import src.interfaces.IMeggyJrRGB;
	/**
	* ...
	* @author Louis Tovar
	*/
	public class MeggyJr_RandomColors extends Shape
	{	
		private var MeggyDark:uint = 0x303030;
		private var MeggyRed:uint = 0xFF0000;
		private var MeggyOrange:uint = 0xFF8000;
		private var MeggyYellow:uint = 0xFFFF00;
		private var MeggyGreen:uint = 0x00FF00;
		private var MeggyBlue:uint = 0x0000FF;
		private var MeggyViolet:uint = 0x800080;
		private var MeggyWhite:uint = 0xFFFFFF;
		private var MeggyDimRed:uint = 0x400000;
		private var MeggyDimOrange:uint = 0x804000;
		private var MeggyDimGreen:uint = 0x004000;
		private var MeggyDimAqua:uint = 0x408080;
		private var MeggyDimBlue:uint = 0x000080;
		private var MeggyDimViolet:uint = 0x400040;
		
		private var MeggyColors:Array = [MeggyDark, MeggyRed, MeggyOrange, MeggyYellow, MeggyGreen, MeggyBlue, MeggyViolet, MeggyWhite, MeggyDimRed, MeggyDimOrange, MeggyDimGreen, MeggyDimAqua, MeggyDimBlue, MeggyDimViolet];
		
		
		private var lastTime:int;
		private var delayTime:int;
		private var interactive:Boolean;
		private var pause:Boolean;
		private var colorRange:int;
		
		private var hardware:IMeggyJrRGB;
		
		public function MeggyJr_RandomColors(p_hardware:IMeggyJrRGB) 
		{
			hardware = p_hardware;
			setup();
		}
		
		private function setup():void
		{
			lastTime = getTimer();
			delayTime = 250;
			interactive = true;
			colorRange = MeggyColors.length;
			
			addEventListener( Event.ENTER_FRAME, onEnterFrame);
		}
		
		private function onEnterFrame(e:Event):void 
		{
			loop();
		}
		
		private function loop():void
		{
			if (lastTime <= getTimer())
			{
					
				var i:int = 0;
				while (i < 8) { 
				  var j:int = 0;
				  while ( j < 8)
				  {
					hardware.mainDisplay.DrawPx(i,j, MeggyColors[ int(Math.random()*MeggyColors.length)-1] );
					hardware.topDisplay.SetAuxLEDs(int(Math.random() * 256) - 1);
					// Randomly pick colors from the color look up table!
					j++;
				  }
				  i++;
				}
				
				hardware.mainDisplay.ShowScreen();
				lastTime += delayTime;
			}
			
		}
		
	}
	
}